﻿@using DeliveryPlus.Web.Classes.Enums
@using DeliveryPlus.Web.DAL
@using DeliveryPlus.Web.DAL.Entities
@model DeliveryPlus.Web.DAL.Entities.Cafe

@{
    ViewBag.Title = Model.Id <= 0 ? "Создание нового кафе" : "Редактирование кафе " + Model.Title;
    Layout = "../Shared/ControlPanelLayout.cshtml";
    var types = (Model.Types ?? "").Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(c => Convert.ToInt16(c)).Select(c => (CafeTypes)c).ToArray();
    var districts = new DeliveryPlusDataContext().Districts.ToList();
}

<form role="form" id="cafe-form" action="/ControlPanel/ManageCafe/Save" method="POST" enctype="multipart/form-data">
    @Html.HiddenFor(m => m.Id)
    <div class="form-group">
        <label for="сafe-title-field">Название</label>
        <input type="text" class="form-control" name="Title" id="cafe-title-field" placeholder="Введите название" value="@Model.Title">
    </div>
    <div class="form-group">
        <label for="сafe-desc-field">Описание (можно использовать HTML разметку)</label>
        <textarea class="form-control" name="Description" placeholder="Введите описание кафе" id="cafe-desc-field">@Model.Description</textarea>
    </div>
    <div class="form-group">
        <label for="сafe-addr-field">Адрес и часы работы (можно использовать HTML разметку)</label>
        <textarea class="form-control" name="Address" placeholder="Введите адрес кафе" id="cafe-addr-field">@Model.Address</textarea>
    </div>
    <div class="form-group">
        <label for="сafe-district-field">Район</label>
        <select id="cafe-district-field" name="DistrictId" class="form-control">
            <option value="-1">Не указан</option>
            @foreach (var district in districts)
            {
                <option value="@district.Id" @(Model.DistrictId == district.Id ? "selected=selected":"")>@district.Title</option>
            }
        </select>
    </div>
    <div class="form-group">
        <label for="">Не отображать в списке</label>
        @Html.CheckBoxFor(m => m.Hidden)
    </div>
    @foreach (CafeTypes type in Enum.GetValues(typeof(CafeTypes)))
    {
        var t = (short) type;
        if (t != 0)
        {
        <div class="form-group">
            <label for="dish-price-field">@type</label>
            <input type="checkbox" class="form-control" name="types-@t" value="@t" @(types.Contains(type) ? "checked=checked":"")/>
        </div>
        }
    }
    <div class="form-group">
        <label for="cafe-logo-field">Логотип</label>
        <input type="file" id="cafe-logo-field"  name="logoFile">
        <p class="help-block">Выберайте только качественную фотографию или логотип</p>
    </div>
    <button type="submit" class="btn btn-default">Сохранить</button>
</form>
<script type="text/javascript">
    $(document).ready(function() {
        $("#cafe-form").validate({
            rules: {
                Title: {
                    required: true,
                    maxlength: 255,
                },
                Description: {
                    required: false,
                    maxlength: 1000,
                },
                Address: {
                    required: false,
                    maxlength: 1000,
                }
            }
        });
    });
</script>
